package com.yiwei.zhh.util;

import android.app.Activity;
import android.content.Intent;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import com.yiwei.zhh.R;
import com.yiwei.zhh.activity.MainActivityNew;
import com.yiwei.zhh.activity.SelectMoneyV3Activity;
import com.yiwei.zhh.activity.StepBankIdentityActivity;
import com.yiwei.zhh.activity.V3AddressIdentityActivity;
import com.yiwei.zhh.activity.V3FaceIdentityOneActivity;
import com.yiwei.zhh.activity.V3IdcardIdentityActivity;
import com.yiwei.zhh.activity.V3TaobaoIdentityActivity;
import com.yiwei.zhh.activity.V3UpdateFinishActivity;
import com.yiwei.zhh.activity.V3XueXinIdentityActivity;
import com.yiwei.zhh.activity.V3YunYingIdentityActivity;
import com.yiwei.zhh.constant.Const;
import com.yiwei.zhh.model.CertificationBasicsModel;
import com.yiwei.zhh.model.DealBeforeV3Model;
import com.yiwei.zhh.view.FlowViewHorizontal;

import java.util.ArrayList;

/**
 * Created by xsooy-pc on 18-7-10.
 */

public class IdentityStepUtil {
    private Activity activity;

    public IdentityStepUtil(Activity activity) {
        this.activity = activity;
    }

    private ArrayList<CertificationBasicsModel.DataBean> oneKeyData;
    private ArrayList<DealBeforeV3Model.DataBean.UplistsBean> SomeKeyData;
    private String isFromOneKey = "-1";
    private String bizType;

    public void setIdentityData(String bizType, TextView txtTitle, FlowViewHorizontal stepView, ArrayList<CertificationBasicsModel.DataBean> oneKeyData, ArrayList<DealBeforeV3Model.DataBean.UplistsBean> SomeKeyData) {
        this.oneKeyData = oneKeyData;
        this.SomeKeyData = SomeKeyData;
        this.bizType = bizType;
        if (oneKeyData != null && oneKeyData.size() != 0) {

            txtTitle.setText("身份认证");
            isFromOneKey = "1";
            if (oneKeyData.size() == 1) {
                String titles[] = new String[2];
                titles[0] = oneKeyData.get(0).name;
                titles[1] = "完成";
                stepView.setProgress(2, 2, titles, null);
            } else {
                int step = 0;
                String titles[] = new String[oneKeyData.size()];
                for (int i = 0; i < oneKeyData.size(); i++) {
                    titles[i] = oneKeyData.get(i).name;
                    if (oneKeyData.get(i).remark.equals(bizType)) {
                        step = (i + 1);
                    }
                }
                stepView.setProgress(step, oneKeyData.size(), titles, null);
            }


        } else if (SomeKeyData != null && SomeKeyData.size() != 0) {
            isFromOneKey = "0";

            int step = 0;
            String titles[] = new String[SomeKeyData.size() + 1];
            for (int i = 0; i < SomeKeyData.size(); i++) {
                titles[i] = SomeKeyData.get(i).name;
                if (SomeKeyData.get(i).remark.equals(bizType)) {
                    step = (i + 1);
                }
            }
            if (step == 0) {
                step = SomeKeyData.size() + 1;
            }
            titles[SomeKeyData.size()] = "完成";
            stepView.setProgress(step, SomeKeyData.size() + 1, titles, null);
        } else {
            stepView.setVisibility(View.GONE);
        }
    }


    public void goToNext() {
        if (isFromOneKey.equals("1")) {

            if (oneKeyData != null && oneKeyData.size() != 0) {
                Intent intent = new Intent();
                int step = 0;
                for (int i = 0; i < oneKeyData.size(); i++) {

                    if (oneKeyData.get(i).remark.equals(bizType)) {
                        step = i + 1;
                        break;
                    }
                }
                if (step < oneKeyData.size()) {
                    switch (oneKeyData.get(step).remark) {
                        case Const.IdentityType.yunyin:
                            intent.setClass(activity, V3YunYingIdentityActivity.class);
                            break;
                        case Const.IdentityType.contacts:
                            intent.setClass(activity, V3AddressIdentityActivity.class);
                            break;
                        case Const.IdentityType.realname:
                            intent.setClass(activity, V3IdcardIdentityActivity.class);
                            break;
                        case Const.IdentityType.taobao:
                            intent.setClass(activity, V3TaobaoIdentityActivity.class);
                            break;
                        case Const.IdentityType.face_detect:
                            intent.setClass(activity, V3FaceIdentityOneActivity.class);
                            break;
                        case Const.IdentityType.xuexin:
                            intent.setClass(activity, V3XueXinIdentityActivity.class);
                            break;
                        case Const.IdentityType.bankcard:
                            intent.setClass(activity, StepBankIdentityActivity.class);
                            break;
                    }
                    intent.putExtra(Const.KEY.ONE_KEY, oneKeyData);
                    activity.startActivity(intent);
                    activity.finish();
                    activity.overridePendingTransition(R.anim.right_enter, R.anim.left_out);

                } else {
                    intent.setClass(activity, SelectMoneyV3Activity.class);
//                intent.putExtra(Const.KEY.ONE_KEY, oneKeyData);
                    activity.startActivity(intent);
                    activity.finish();
                    activity.overridePendingTransition(R.anim.right_enter, R.anim.left_out);
                }

            }

        } else if (isFromOneKey.equals("0")) {
            if (SomeKeyData != null && SomeKeyData.size() != 0) {
                Intent intent = new Intent();
                int step = 0;
                for (int i = 0; i < SomeKeyData.size(); i++) {

                    if (SomeKeyData.get(i).remark.equals(bizType)) {
                        step = i + 1;
                        break;
                    }
                }
                if (step < SomeKeyData.size()) {
                    switch (SomeKeyData.get(step).remark) {
                        case Const.IdentityType.yunyin:
                            intent.setClass(activity, V3YunYingIdentityActivity.class);
                            break;
                        case Const.IdentityType.contacts:
                            intent.setClass(activity, V3AddressIdentityActivity.class);
                            break;
                        case Const.IdentityType.realname:
                            intent.setClass(activity, V3IdcardIdentityActivity.class);
                            break;
                        case Const.IdentityType.taobao:
                            intent.setClass(activity, V3TaobaoIdentityActivity.class);
                            break;
                        case Const.IdentityType.face_detect:
                            intent.setClass(activity, V3FaceIdentityOneActivity.class);
                            break;
                        case Const.IdentityType.xuexin:
                            intent.setClass(activity, V3XueXinIdentityActivity.class);
                            break;
                        case Const.IdentityType.bankcard:
                            intent.setClass(activity, StepBankIdentityActivity.class);
                            break;
                    }

                    intent.putExtra(Const.KEY.SOME_IDENTITY_KEY, SomeKeyData);
                    activity.startActivity(intent);
                    activity.finish();
                    activity.overridePendingTransition(R.anim.right_enter, R.anim.left_out);

                } else {
                    intent.setClass(activity, V3UpdateFinishActivity.class);
                    intent.putExtra(Const.KEY.SOME_IDENTITY_KEY, SomeKeyData);
                    activity.startActivity(intent);
                    activity.finish();
                    activity.overridePendingTransition(R.anim.right_enter, R.anim.left_out);

                }
            }
        } else {
            activity.finish();
            activity.overridePendingTransition(R.anim.right_enter, R.anim.left_out);
        }
    }
}
